package com.seirsoft.cookingtime.controller;

import com.seirsoft.cookingtime.view.IDlgBase;
import com.seirsoft.cookingtime.view.IDlgDisplayTime;
import com.seirsoft.framework.util.GUIUtil;

public class CtlDlgDisplayTime extends CtlDlgBase
{
	private long seconds = 0;

	public CtlDlgDisplayTime(IDlgBase dlgBase, long lSeconds) {
		super(dlgBase);
		
		seconds = lSeconds;
	}
	
	private IDlgDisplayTime getDlgDisplayTime()
	{
		return (IDlgDisplayTime) super.m_dialog;
	}

	protected String getDialogTitle() {
		return Messages.getMessageString("DlgDisplayTime.Title"); //$NON-NLS-1$
	}
	

	
	@Override
	public void fireEventUICreated() {
		super.m_dialog.setTitle(this.getDialogTitle());
		super.m_dialog.setSize(200, 100);
		
		this.getDlgDisplayTime().startTime();
	}

	@Override
	public void fireEventDialogClosed() {
		getDlgDisplayTime().stopTime();
		super.fireEventDialogClosed();
	}


	public void fireEventTimerRun() {
		if(!super.m_dialog.isDisposed())
		{
			this.getDlgDisplayTime().refreshTime(seconds);
			
			seconds --;
			if(seconds < 0)
			{
				this.getDlgDisplayTime().stopTime();
				
				for(int i=0; i<5; i++)
				{
					GUIUtil.playSound(1300,1000);
				}
			}

		}
	}
}
